<?php
class Lang{
    
    protected static $_instance = null;
    static protected $_dictionary = null;
    
    protected function __construct(){
		if(is_null(self::$_dictionary))
			throw new Exception('Dictionary not initialized');    	
    }
    
	static public function getInstance(){
        if(is_null(self::$_instance))
           self::$_instance = new self();
        return self::$_instance;   
    }

    static public function setDictionary(Config_Abstract $dictionary){
    	self::$_dictionary = $dictionary;
    }
    
    public function __get($key){
    	if(isset(self::$_dictionary[$key]))
    		return self::$_dictionary[$key];
    	else 
    		return '['.$key.']';	
    }
    
    public function getJson(){
        return json_encode(self::$_dictionary->__toArray());
    }
    
    public function getJsObject(){
    	$items = array();
    	foreach (self::$_dictionary as $k=>$v)
    		$items[]= $k.':"'.$v.'"';
   
    	return '{'.implode(',', $items).'}';	
    }
}